<?php
class Admin_CrudController extends Zend_Controller_Action
{
	protected $_table;
	protected $_view;

	public function init() {
		if('index' !=$this->_request->getActionName()) {
			$table = $this->_getParam('table',false);
			if(!$table) {
				return $this->_redirect('/crud');		
			}
		
			try {
				$this->_table = Wmp_Db_Table_Generic::getInstance($table);
			} catch (Exception $e) {
				return $this->redirect('/crud');
			}
		
			$this->_tableName = $table;
		
			$this->view->table = $table;
		}
		//Zend_Debug::dump($this->_table); exit(1);
	}
	//public function postDispatch(){$this->_table="jjjjsqsqlsq";}
	public function indexAction() {
		$this->view->toto = $this->_table;
		$this->view->tables = Zend_Registry::get('db')->listTables();
	}
	
	public function listAction() {
		Zend_Debug::dump($this->_table); exit;
		
		//$offset = $this->_paginate();
		$this->view->fields = $this->_table->getFields();
		$this->view->primary = $this->_table->getPrimay();
		$this->view->rows = $this->_table->fetchAll(null,null,30,$offset);
	}
	public function createAction() {
		$this->view->values = array();

		if('post'==strtolower($_SERVER['REQUEST_METHOD'])) {
			$this->process();
		}
	
		$this->view->fields = $this->_table->getFields();
	
		$this->render('form');
	}
	/*public function readAction();
	public function updateAction();
	public function deleteAction();
	*/
}